﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace DZPK
{
    public class PlayerLoginConfig
    {
        public string weiboUsername;
        public string weiboPassword;
        public string dzpkUsername;
        public string dzpkUserKey;
        public int    dzpkMid;
        public long   UserKeyLastUpdataTimeStamp;
    }

    public class PlayerManager
    {
        public ConcurrentDictionary<int, Player> midToPlayerMap;
        public List<PlayerLoginConfig> playerLoginConfigList;
        public string playerConfigFilename;

        public PlayerManager()
        {
            midToPlayerMap = new ConcurrentDictionary<int, Player>();
            playerConfigFilename = "PlayerLoginConfig.xml";
        }

        public void ReleasePlayerSocket(int mid)
        {
            
        }

        public void MarkPlayerHeartBeatToServer()
        {
            foreach (Player player in midToPlayerMap.Values)
            {
                player.MarkPlayerHeartBeatToServer();
            }
        }

        public Player GetPlayerFromMid(int mid)
        {
            Player player = null;
            
            if (midToPlayerMap.TryGetValue(mid, out player))
            {
                return player;
            }

            return null;
        }

        public void GetPlayerLoginKeyFromConfigFile()
        {
            XmlDocument dom = new XmlDocument();
            dom.Load(playerConfigFilename);

            XmlNodeList playerList = dom.SelectSingleNode("PlayerList").ChildNodes;
            foreach (XmlNode playerNode in playerList)
            {
                PlayerLoginConfig oConfig = new PlayerLoginConfig();

                playerLoginConfigList.Add(oConfig);
            }
        }

        public void InitializePlayers()
        {
            
        }
    }
}
